;(function() {
	Nokia.NewsItemView = Nokia.View.extend({
		
		init: function() {
			var instance = this;
			
			this.newsElement = this.getContainer().find('#news-item-content');
			
			this.newsOpenButton = new Nokia.Button({
				element: '#news-item-open-button',
				label: 'News Detail',
				width: '50%',
				click: function() {
					instance.openInWebBrowser();
				}
			});
		},
		
		openInWebBrowser: function() {
			widget.openURL(this.newsItem.unescapedUrl);
		},
		
		showNews: function(newsItem) {
			this.newsItem = newsItem;

			var newsHTML = Nokia.GBCServices.getServiceItemSnippet(newsItem);
				
			newsHTML += '<div class="item-detail-text" id="news-item-text"></div>' + 
				'<p id="news-item-text-content">' + 
				(newsItem.imageUrl ? 
					'<img onload="Nokia.GBCUtils.normalizeImageWidth(event)" class="clearer item-detail-photo" src="' + newsItem.imageUrl + '" />'
					:
					''
				) + 
				newsItem.content + '<span class="clearer"></span></p>';

			this.newsElement.html(newsHTML);
			
			new Nokia.TextLabel({
				element: '#news-item-text',
				content: '#news-item-text-content'
			});
		},
		
		show: function(newsItem) {
			var instance = this;
			var template = this.getTemplate();
			var topBar = template.getHeaderTopBar();
			var viewManager = template.getViewManager();
			
			var defaultTopItems = GBC.getDefaultTopItems();
			
			defaultTopItems[0] = {classname: 'nokia-template-header-icon-back', callback: function() { viewManager.back() }};
			
			topBar.setItems(defaultTopItems);
			
			this.showNews(newsItem);
			
			this.getContainer().show();
		}
	});
})();